# python列表和PHParray很像
bicycles = ["trek", "cannondale", "redline", "specialized"]
print(bicycles)

# 访问列表中的元素0
print(bicycles[0])

print(bicycles[0].title())

# 访问列表中最后一个元素
print(bicycles[-1])
print(bicycles[-4])

bicycles = ["trek", "cannondale", "redline", "specialized"]
message = "My first bicycle was a " + bicycles[0].title() + "."
print(message)

motorcycles = ["honda", "yamaha", "suzuki"]
# ['honda', 'yamaha', 'suzuki']
print(motorcycles)
motorcycles[0] = "ducati"
# ['ducati', 'yamaha', 'suzuki']
print(motorcycles)

# 追加元素，添加到list尾部
motorcycles = ["honda", "yamaha", "suzuki"]
motorcycles.append("ducati")
# ['honda', 'yamaha', 'suzuki', 'ducati']
print(motorcycles)

# 插入 TODO
motorcycles = ["honda", "yamaha", "suzuki"]
# 插入的位置insert()
motorcycles.insert(0, "ducati")
# ['ducati', 'honda', 'yamaha', 'suzuki']
print(motorcycles)

# del()
# pop()
# remove()
# 删除 del 知道索引可以删除任意位置
motorcycles = ["honda", "yamaha", "suzuki"]

del motorcycles[0]
# ['yamaha', 'suzuki']
print(motorcycles)

# pop 删除 list 尾部元素
motorcycles = ["honda", "yamaha", "suzuki"]
popped_motorcycle = motorcycles.pop()
# pop后的list['honda', 'yamaha']
print(motorcycles)
# pop的元素是suzuki
print(popped_motorcycle)

# pop(0) 删除 list 头部元素，可以带下标
motorcycles = ["honda", "yamaha", "suzuki"]
first_owned = motorcycles.pop(0)
# The first motorcycle I owned was a Honda.
print("The first motorcycle I owned was a " + first_owned.title() + ".")
print("\r")

# remove() 删除指定元素，不带下标
# 方法remove() 只删除第一个指定的值。如果要删除的值可能在列表中出现多次，就需要使用循环来判断是否删除了所有这样的值。
motorcycles = ["honda", "yamaha", "suzuki", "ducati"]
# ['honda', 'yamaha', 'suzuki', 'ducati']
print(motorcycles)
motorcycles.remove("ducati")
# ['honda', 'yamaha', 'suzuki']
print(motorcycles)
